package com.itheima.exception;


import com.itheima.common.R;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(NologinException.class)
    public R<String> NologinExceptionHandler(NologinException ex){
         return  R.error("NOTLOGIN");
    }
    @ExceptionHandler(NoDataException.class)
    public R NoDataExceptionHandler(NoDataException ex){
        return  R.error("没有数据");
    }
    @ExceptionHandler(OtherException.class)
    public  R OtherExceptionHandler(Exception ex){
        return  R.error("程序出错了,请联系管理员");
    }

}
